/*   1:    */
package com.course.utils.binary;
/*   2:    */
/*   3:    */

/*   4:    */
/*   5:    */ public class Base64
        /*   6:    */ extends BaseNCodec
        /*   7:    */ {

    /*  11: 71 */   static final byte[] CHUNK_SEPARATOR = {13, 10};
    /*  12: 80 */   private static final byte[] STANDARD_ENCODE_TABLE = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47};
    /*  13: 93 */   private static final byte[] URL_SAFE_ENCODE_TABLE = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 45, 95};
    /*  14:112 */   private static final byte[] DECODE_TABLE = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
    /*  15:    */   private static final int MASK_6BITS = 63;
    /*  16:    */   private final byte[] encodeTable;
    /*  17:140 */   private final byte[] decodeTable = DECODE_TABLE;
    /*  18:    */   private final byte[] lineSeparator;
    /*  19:    */   private final int decodeSize;
    /*  20:    */   private final int encodeSize;

    /*  21:    */
    /*  22:    */
    public Base64()
    /*  23:    */ {
        /*  24:170 */
        this(0);
        /*  25:    */
    }

    /*  26:    */
    /*  27:    */
    public Base64(boolean urlSafe)
    /*  28:    */ {
        /*  29:189 */
        this(76, CHUNK_SEPARATOR, urlSafe);
        /*  30:    */
    }

    /*  31:    */
    /*  32:    */
    public Base64(int lineLength)
    /*  33:    */ {
        /*  34:212 */
        this(lineLength, CHUNK_SEPARATOR);
        /*  35:    */
    }

    /*  36:    */
    /*  37:    */
    public Base64(int lineLength, byte[] lineSeparator)
    /*  38:    */ {
        /*  39:239 */
        this(lineLength, lineSeparator, false);
        /*  40:    */
    }

    /*  41:    */
    /*  42:    */
    public Base64(int lineLength, byte[] lineSeparator, boolean urlSafe)
    /*  43:    */ {
        /*  44:270 */
        super(3, 4, lineLength, lineSeparator == null ? 0 : lineSeparator.length);
        /*  45:275 */
        if (lineSeparator != null)
            /*  46:    */ {
            /*  47:276 */
            if (containsAlphabetOrPad(lineSeparator))
                /*  48:    */ {
                /*  49:277 */
                String sep = StringUtils.newStringUtf8(lineSeparator);
                /*  50:278 */
                throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + sep + "]");
                /*  51:    */
            }
            /*  52:280 */
            if (lineLength > 0)
                /*  53:    */ {
                /*  54:281 */
                this.encodeSize = (4 + lineSeparator.length);
                /*  55:282 */
                this.lineSeparator = new byte[lineSeparator.length];
                /*  56:283 */
                System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
                /*  57:    */
            }
            /*  58:    */
            else
                /*  59:    */ {
                /*  60:285 */
                this.encodeSize = 4;
                /*  61:286 */
                this.lineSeparator = null;
                /*  62:    */
            }
            /*  63:    */
        }
        /*  64:    */
        else
            /*  65:    */ {
            /*  66:289 */
            this.encodeSize = 4;
            /*  67:290 */
            this.lineSeparator = null;
            /*  68:    */
        }
        /*  69:292 */
        this.decodeSize = (this.encodeSize - 1);
        /*  70:293 */
        this.encodeTable = (urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE);
        /*  71:    */
    }

    /*  72:    */
    /*  73:    */
    public boolean isUrlSafe()
    /*  74:    */ {
        /*  75:303 */
        return this.encodeTable == URL_SAFE_ENCODE_TABLE;
        /*  76:    */
    }

    /*  77:    */
    /*  78:    */   void encode(byte[] in, int inPos, int inAvail, BaseNCodec.Context context)
    /*  79:    */ {
        /*  80:329 */
        if (context.eof) {
            /*  81:330 */
            return;
            /*  82:    */
        }
        /*  83:334 */
        if (inAvail < 0)
            /*  84:    */ {
            /*  85:335 */
            context.eof = true;
            /*  86:336 */
            if ((0 == context.modulus) && (this.lineLength == 0)) {
                /*  87:337 */
                return;
                /*  88:    */
            }
            /*  89:339 */
            byte[] buffer = ensureBufferSize(this.encodeSize, context);
            /*  90:340 */
            int savedPos = context.pos;
            /*  91:341 */
            switch (context.modulus)
                /*  92:    */ {
                /*  93:    */
                case 0:
                    /*  94:    */
                    break;
                /*  95:    */
                case 1:
                    /*  96:346 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea >> 2 & 0x3F)];
                    /*  97:    */
                    /*  98:348 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea << 4 & 0x3F)];
                    /*  99:350 */
                    if (this.encodeTable == STANDARD_ENCODE_TABLE)
                        /* 100:    */ {
                        /* 101:351 */
                        buffer[(context.pos++)] = 61;
                        /* 102:352 */
                        buffer[(context.pos++)] = 61;
                        /* 103:    */
                    }
                    /* 104:    */
                    break;
                /* 105:    */
                case 2:
                    /* 106:357 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea >> 10 & 0x3F)];
                    /* 107:358 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea >> 4 & 0x3F)];
                    /* 108:359 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea << 2 & 0x3F)];
                    /* 109:361 */
                    if (this.encodeTable == STANDARD_ENCODE_TABLE) {
                        /* 110:362 */
                        buffer[(context.pos++)] = 61;
                        /* 111:    */
                    }
                    /* 112:    */
                    break;
                /* 113:    */
                default:
                    /* 114:366 */
                    throw new IllegalStateException("Impossible modulus " + context.modulus);
                    /* 115:    */
            }
            /* 116:368 */
            context.currentLinePos += context.pos - savedPos;
            /* 117:370 */
            if ((this.lineLength > 0) && (context.currentLinePos > 0))
                /* 118:    */ {
                /* 119:371 */
                System.arraycopy(this.lineSeparator, 0, buffer, context.pos, this.lineSeparator.length);
                /* 120:372 */
                context.pos += this.lineSeparator.length;
                /* 121:    */
            }
            /* 122:    */
        }
        /* 123:    */
        else
            /* 124:    */ {
            /* 125:375 */
            for (int i = 0; i < inAvail; i++)
                /* 126:    */ {
                /* 127:376 */
                byte[] buffer = ensureBufferSize(this.encodeSize, context);
                /* 128:377 */
                context.modulus = ((context.modulus + 1) % 3);
                /* 129:378 */
                int b = in[(inPos++)];
                /* 130:379 */
                if (b < 0) {
                    /* 131:380 */
                    b += 256;
                    /* 132:    */
                }
                /* 133:382 */
                context.ibitWorkArea = ((context.ibitWorkArea << 8) + b);
                /* 134:383 */
                if (0 == context.modulus)
                    /* 135:    */ {
                    /* 136:384 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea >> 18 & 0x3F)];
                    /* 137:385 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea >> 12 & 0x3F)];
                    /* 138:386 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea >> 6 & 0x3F)];
                    /* 139:387 */
                    buffer[(context.pos++)] = this.encodeTable[(context.ibitWorkArea & 0x3F)];
                    /* 140:388 */
                    context.currentLinePos += 4;
                    /* 141:389 */
                    if ((this.lineLength > 0) && (this.lineLength <= context.currentLinePos))
                        /* 142:    */ {
                        /* 143:390 */
                        System.arraycopy(this.lineSeparator, 0, buffer, context.pos, this.lineSeparator.length);
                        /* 144:391 */
                        context.pos += this.lineSeparator.length;
                        /* 145:392 */
                        context.currentLinePos = 0;
                        /* 146:    */
                    }
                    /* 147:    */
                }
                /* 148:    */
            }
            /* 149:    */
        }
        /* 150:    */
    }

    /* 151:    */
    /* 152:    */   void decode(byte[] in, int inPos, int inAvail, BaseNCodec.Context context)
    /* 153:    */ {
        /* 154:426 */
        if (context.eof) {
            /* 155:427 */
            return;
            /* 156:    */
        }
        /* 157:429 */
        if (inAvail < 0) {
            /* 158:430 */
            context.eof = true;
            /* 159:    */
        }
        /* 160:432 */
        for (int i = 0; i < inAvail; i++)
            /* 161:    */ {
            /* 162:433 */
            byte[] buffer = ensureBufferSize(this.decodeSize, context);
            /* 163:434 */
            byte b = in[(inPos++)];
            /* 164:435 */
            if (b == 61)
                /* 165:    */ {
                /* 166:437 */
                context.eof = true;
                /* 167:438 */
                break;
                /* 168:    */
            }
            /* 169:440 */
            if ((b >= 0) && (b < DECODE_TABLE.length))
                /* 170:    */ {
                /* 171:441 */
                int result = DECODE_TABLE[b];
                /* 172:442 */
                if (result >= 0)
                    /* 173:    */ {
                    /* 174:443 */
                    context.modulus = ((context.modulus + 1) % 4);
                    /* 175:444 */
                    context.ibitWorkArea = ((context.ibitWorkArea << 6) + result);
                    /* 176:445 */
                    if (context.modulus == 0)
                        /* 177:    */ {
                        /* 178:446 */
                        buffer[(context.pos++)] = ((byte) (context.ibitWorkArea >> 16 & 0xFF));
                        /* 179:447 */
                        buffer[(context.pos++)] = ((byte) (context.ibitWorkArea >> 8 & 0xFF));
                        /* 180:448 */
                        buffer[(context.pos++)] = ((byte) (context.ibitWorkArea & 0xFF));
                        /* 181:    */
                    }
                    /* 182:    */
                }
                /* 183:    */
            }
            /* 184:    */
        }
        /* 185:458 */
        if ((context.eof) && (context.modulus != 0))
            /* 186:    */ {
            /* 187:459 */
            byte[] buffer = ensureBufferSize(this.decodeSize, context);
            /* 188:463 */
            switch (context.modulus)
                /* 189:    */ {
                /* 190:    */
                case 1:
                    /* 191:    */
                    break;
                /* 192:    */
                case 2:
                    /* 193:469 */
                    context.ibitWorkArea >>= 4;
                    /* 194:470 */
                    buffer[(context.pos++)] = ((byte) (context.ibitWorkArea & 0xFF));
                    /* 195:471 */
                    break;
                /* 196:    */
                case 3:
                    /* 197:473 */
                    context.ibitWorkArea >>= 2;
                    /* 198:474 */
                    buffer[(context.pos++)] = ((byte) (context.ibitWorkArea >> 8 & 0xFF));
                    /* 199:475 */
                    buffer[(context.pos++)] = ((byte) (context.ibitWorkArea & 0xFF));
                    /* 200:476 */
                    break;
                /* 201:    */
                default:
                    /* 202:478 */
                    throw new IllegalStateException("Impossible modulus " + context.modulus);
                    /* 203:    */
            }
            /* 204:    */
        }
        /* 205:    */
    }

    /* 206:    */
    /* 207:    */
    /* 212:    */
    /* 286:    */
    public static byte[] decodeBase64(byte[] base64Data)
    /* 287:    */ {
        /* 288:697 */
        return new Base64().decode(base64Data);
        /* 289:    */
    }

    /* 325:    */
    /* 326:    */
    protected boolean isInAlphabet(byte octet)
    /* 327:    */ {
        /* 328:772 */
        return (octet >= 0) && (octet < this.decodeTable.length) && (this.decodeTable[octet] != -1);
        /* 329:    */
    }
    /* 330:    */
}



/* Location:           C:\Users\Fenix\Downloads\commons-codec-1.8.jar

 * Qualified Name:     org.apache.commons.codec.binary.Base64

 * JD-Core Version:    0.7.0.1

 */